import numpy as np
import matplotlib.pyplot as plt

# 定义信号参数
frequency = 500e3  # 频率为 500 KHz
amplitude = 5  # 幅值为 5 V
offset = 2.5  # 偏置为 2.5 V
duty_cycle = 15  # 占空比为 15%

# 定义时间轴
t = np.linspace(0, 1/frequency, 1000)

# 生成方波信号
signal = amplitude * (np.mod(t, 1/frequency) < (duty_cycle/100)) + offset

# 绘制信号图形
plt.plot(t, signal)
plt.xlabel('Time (s)')
plt.ylabel('Amplitude (V)')
plt.title('Square Wave')
plt.show()